<?php


/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Badge
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
?>
<script type="text/javascript">

var currentOrder = '<?php echo $this->order ?>';
var currentOrderDirection = '<?php echo $this->order_direction ?>';
var changeOrder = function(order, default_direction){
  // Just change direction
  if( order == currentOrder ) {
    $('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
  } else {
    $('order').value = order;
    $('order_direction').value = default_direction;
  }
  $('filter_form').submit();
}


  en4.core.runonce.add(function(){$$('th.admin_table_short input[type=checkbox]').addEvent('click', function(){ $$('input[type=checkbox]').set('checked', $(this).get('checked', false)); })});

  var delectSelected =function(){
    var checkboxes = $$('input[type=checkbox]');
    var selecteditems = [];

    checkboxes.each(function(item, index){
      var checked = item.get('checked', false);
      var value = item.get('value', false);
      if (checked == true && value != 'on'){
        selecteditems.push(value);
      }
    });

    $('ids').value = selecteditems;
    $('delete_selected').submit();
  }

</script>

<h2><?php echo $this->translate("Badges Plugin") ?></h2>

<?php if( count($this->navigation) ): ?>
  <div class='tabs'>
    <?php
      // Render the menu
      //->setUlClass()
      echo $this->navigation()->menu()->setContainer($this->navigation)->render()
    ?>
  </div>
<?php endif; ?>

<p>
  <?php echo $this->translate("This page allows to you manage awards you have given to your members.") ?>
</p>
<br />

<div>
    <?php echo $this->htmlLink($this->url(array('action'=>'create')), 
      $this->translate('Post New Award'),
      array('class' => 'buttonlink icon_badge_award_create')
    )?> 
</div>
<br />

<div class='admin_search'>
  <?php echo $this->formFilter->render($this) ?>
</div>

<br />



<?php if( count($this->paginator) ): ?>

<div class='admin_results'>
  <div>
    <?php $badgeCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s award found", "%s awards found", $badgeCount), ($badgeCount)) ?>
  </div>
  <div>
    <?php // echo $this->paginationControl($this->paginator, null, null, array('params'=>$this->params)); ?>
    
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>  
    
  </div>
</div>
<br />

<table class='admin_table'>
  <thead>
    <tr>
      <th class='admin_table_short'><a href="javascript:void(0);" onclick="javascript:changeOrder('award_id', 'ASC');">ID</a></th>
      <th><?php echo $this->translate('Icon');?></th>
      <th><?php echo $this->translate('Badge');?></th>
      <th><?php echo $this->translate('Member');?></th>
      <th><a href="javascript:void(0);" onclick="javascript:changeOrder('title', 'ASC');"><?php echo $this->translate("Award Title") ?></a></th>
      <th><?php echo $this->translate('Expiration');?></th>
      <th><?php echo $this->translate('Featured'); ?></th>
      <th><?php echo $this->translate("Options") ?></th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($this->paginator as $award): $badge = $award->getBadge(); ?>
      <tr>
        <td><?php echo $award->getIdentity(); ?></td>
        <td><?php echo $this->htmlLink($badge->getHref(), $this->itemPhoto($badge, 'thumb.icon')); ?>
        <td><?php echo $badge->__toString(); ?>
        </td>  
        <td>
          <?php echo $award->getUser()->__toString(); ?>
        </td>  
        <td><?php echo $this->htmlLink($award->getHref(), $award->getTitle(), array('target'=>'_blank'))?>
          <?php // echo $this->viewMore($award->getDescription());?>
        </td>
        <td>
          <?php if ($award->end_settings): ?>
            <?php echo $this->locale()->toDateTime($award->end_time) ?>
          <?php else: ?>
            <?php echo $this->translate('N/A'); ?>
          <?php endif;?>  
        </td>
        <td>
          <?php echo $this->translate($award->featured ? 'Yes' : 'No');?>
        </td>
        <td>
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'awards', 'action' => 'edit', 'award_id' => $award->award_id),
            $this->translate("edit"),
            array('class' => '')) ?>
          |
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'awards', 'action' => 'delete', 'award_id' => $award->award_id),
            $this->translate("delete"),
            array('class' => 'smoothbox')) ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

<br />

<?php else:?>
  <div class="tip">
    <span>
      <?php echo $this->translate("There are no awards given yet.") ?>
    </span>
  </div>
<?php endif; ?>
